package com.skrabacz.kinetic.buisness.logic;

import javax.management.InvalidAttributeValueException;

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

public class MatrixShould {

	private Board board;
	private Point node;

	@Before
	public void setUpBeforeSingleTest() {
		board = new Matrix();
		node = new Node();
	}

	@Test(expected = InvalidAttributeValueException.class)
	public void throwsExcepctionIfWasToFewCoordinates() throws Exception {
		board.getPoint(1);
	}

	@Test(expected = IndexOutOfBoundsException.class)
	public void throwsExcepctionIfCoordinatesWasWrong() throws Exception {
		board.getPoint(1, 2);
	}

	@Test
	public void returnPointIfCoordinateWasCorrect() throws Exception {
		assertNotNull(new Matrix(createMatrixWithPoint(new Node(), 0, 0)).getPoint(0, 0));
	}

	@Test
	public void updateMatrixParamsAfterCreation() throws Exception {
		board = new Matrix(createMatrix(1, 2));
		assertEquals(2, board.getHeight());
	}

	@Test
	public void returnCorrectPointFromCorrectCoordination() throws Exception {
		board = new Matrix(createMatrixWithPoint(node, 0, 0));
		assertEquals(node, board.getPoint(0, 0));
	}

	private Point[][] createMatrixWithPoint(Point point, int cor1, int cor2) {
		Point[][] matrix = createMatrix(cor1 + 1, cor2 + 1);
		matrix[cor1][cor2] = point;
		return matrix;
	}

	private Point[][] createMatrix(int widht, int height) {
		Point[][] matrix = new Node[height][];
		for (int i = 0; i < height; i++) {
			matrix[i] = new Node[widht];
		}
		return matrix;
	}

}
